<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试项目告警API</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        .test-button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
        }
        .test-button:hover {
            background: #0056b3;
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 4px;
            white-space: pre-wrap;
            font-family: monospace;
        }
        .error {
            background: #f8d7da;
            color: #721c24;
        }
        .success {
            background: #d4edda;
            color: #155724;
        }
    </style>
</head>
<body>
    <h1>项目告警API测试</h1>
    
    <div class="test-section">
        <h2>测试告警API</h2>
        <button class="test-button" onclick="testWarningAlerts()">获取警告告警</button>
        <button class="test-button" onclick="testUrgentAlerts()">获取紧急告警</button>
        <button class="test-button" onclick="testPaginatedAlerts()">测试分页</button>
        <div id="alertsResult" class="result"></div>
    </div>

    <script>
        const API_BASE_URL = 'http://43.134.133.173:5500/api/v1';
        
        async function makeRequest(url, options = {}) {
            try {
                const response = await fetch(url, {
                    headers: {
                        'Content-Type': 'application/json',
                        ...options.headers
                    },
                    ...options
                });
                
                const data = await response.json();
                return { success: true, data, status: response.status };
            } catch (error) {
                return { success: false, error: error.message };
            }
        }
        
        function displayResult(elementId, result) {
            const element = document.getElementById(elementId);
            if (result.success) {
                element.className = 'result success';
                element.textContent = JSON.stringify(result.data, null, 2);
            } else {
                element.className = 'result error';
                element.textContent = `错误: ${result.error}`;
            }
        }
        
        async function testWarningAlerts() {
            console.log('测试警告告警...');
            const result = await makeRequest(`${API_BASE_URL}/alerts/projects?severity=WARNING&page_size=10`);
            displayResult('alertsResult', result);
        }
        
        async function testUrgentAlerts() {
            console.log('测试紧急告警...');
            const result = await makeRequest(`${API_BASE_URL}/alerts/projects?severity=URGENT&page_size=10`);
            displayResult('alertsResult', result);
        }
        
        async function testPaginatedAlerts() {
            console.log('测试分页告警...');
            const result = await makeRequest(`${API_BASE_URL}/alerts/projects?severity=WARNING&page=1&page_size=5`);
            displayResult('alertsResult', result);
        }
        
        // 页面加载时自动测试
        window.onload = function() {
            console.log('页面加载完成，可以开始测试');
        };
    </script>
</body>
</html>